package com.atguigu.gmall.pms.vo;

import com.atguigu.gmall.pms.entity.SpuAttrValueEntity;
import lombok.Data;
import org.apache.commons.lang.StringUtils;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**day3
 * 用来接受
 * "baseAttrs": [{
 * 		"id": 1,
 * 		"name": "上市年份",
 * 		"valueSelected": ["2019"]
 *        }, 中的
 * "valueSelected"
 */

public class SpuAttrValueVo extends SpuAttrValueEntity {
    //private List<String> valueSelected;

    //前端传过来的参数名就叫valueSelected,
    // 所以会直接调用set方法来赋值，
    // 之后将拼接好的字符串赋值给父类的attrvalue
    public void setValueSelected(List<String> valueSelected) {
        if(CollectionUtils.isEmpty(valueSelected)){
            return;
        }
        //将valueSelected属性赋给父类的attrvalue
        this.setAttrValue(StringUtils.join(valueSelected,","));
    }
 }
